<?php

/************************
* SECURITY CHECK
************************/
if (!defined('PUBLIC_HTML'))
{
	exit;
}

/************************
* CONTACT PAGE IS ACTIVE?
************************/
if (!$config->get('photo_album_active'))
{
	redirect($main_path);
	exit;
}

/************************
* PREPATIONS
************************/
$p_number	= (!isset($url_params[($url_offset + 1)])) ? '1' : $url_params[($url_offset + 1)];

/************************
* TEMPLATE PREPATIONS
************************/
$tpl_content = new TemplatePower(PATH_HTML . 'photos_body' . EXT_HTML);
$tpl_content->prepare();

$tpl_content_vars = array(
	'PAGE_TITLE'	=> $page_title,
	'PAGE_CONTENT'	=> $page_content,
);

$tpl_content->assign($tpl_content_vars);

/************************
* GENERATE PAGINATION
************************/

// Count the amount of photos
$x_photos	= $db->sql_count(TABLE_PHOTOS, 'pht_active', '1');

// Define the current page
$x_page	  	= $p_number;

// Get the photos per page limit
$p_limit	= $config->get('photo_album_limit');

// Set the right offset for the query
$p_offset	= (($p_number-1) * $p_limit);

// Count the amount of pages to generate
$x_pages	= ceil($x_photos / $p_limit);

// Loop the pages into a pagination
for ($i=1;$i<=$x_pages;$i++)
{
	$tpl_content->newBlock("PAGINATION");
	$tpl_content_vars = array(
		'PN_NUMBER'	=> $i,
		'PN_LINK'	=> $page_var.'/'.$i,
	);
	$tpl_content->assign($tpl_content_vars);
}

/************************
* GET PHOTOS FROM ALBUM
************************/
$get_photos	=	"
				SELECT		*
				FROM		" . TABLE_PHOTOS . "
				WHERE		pht_active		= '1'
				ORDER BY	pht_id
				ASC
				LIMIT		" . $p_offset . ", " . $p_limit . "
				";
$sql_photos =	$db->sql_query($get_photos);
while ($row_photos = $db->sql_fetch_assoc($sql_photos))
{
	$tpl_content->newBlock("GET PHOTOS");
	$photo_title = $row_photos['pht_title'];
	$photo_descr = $row_photos['pht_description'];
	$photo_fancy = ($photo_descr == '') ? $photo_title : $photo_title.' - '.$photo_descr;
	$photo_link	 = $media_dir . 'photos/' . $row_photos['pht_filename'];
	$photo_thumb = (!empty($row_photos['pht_filename_thumb'])) ? $media_dir . 'photos/' . $row_photos['pht_filename_thumb'] : $photo_link;
	$photo_show	 = $image->display($photo_thumb, '.fotoalbum', '', $photo_title, 'alt="'.$photo_title.'"');
	$tpl_content_vars = array(
		'PHOTO_TITLE'	=> $photo_title,
		'PHOTO_LINK'	=> $photo_link,
		'PHOTO_SHOW'	=> $photo_show,
	 	'PHOTO_FANCY'	=> $photo_fancy,
	);
	$tpl_content->assign($tpl_content_vars);
	
}
//$tpl_content->printToScreen();

?>